/**
 * 首页接口  传参数；展示对应数据
 */

//  跳转查询上游报价
function searchClick() {
    document.location.href = '../referPhonePrice/referIphonPrices.html';
}


//  跳转订单处理
function OrderHanding() {
    document.location.href = '../orderHanding/orderHanding.html';
}

//  快递收回 订单管理
// function skipExpress() {
//     document.location.href = '../orderHanding/expressHanding.html';
// }

//  跳转订单管理
function OrderManage() {
    document.location.href = '../orderManage/orderManage.html';

}

//  跳转账号管理
function ITunes() {
    console.log('账号管理')
    document.location.href = '1.html';
}

//  跳转活动中心
function ActivityCenter() {
    console.log('新建活动')
    document.location.href = '../activity/activity.html'
}

//  跳转我的钱包
function myWlallet() {
    document.location.href = '../myWallet/mywallet.html'
}

//  卖给上游
function sellUpstream() {
    document.location.href = '../sellUpstream/sellOrder/sellOrder.html'
}

// 确定事件 点击向后端发送
function sureClick() {
    var firstDate = new Date();
    firstDate.setDate(1); //第一天


    var nowData=getNowFormatDate();

    var mothonFrist = new XDate(firstDate).toString('yyyy-MM-dd');

    var beginTimeStr = document.getElementById("showDate").innerHTML;
    var endADateStr = document.getElementById("endADate").innerHTML;


    if (beginTimeStr == '选择开始日期') {
        beginTimeStr=mothonFrist;
    } else {
        beginTimeStr = beginTimeStr.replace('年', '-');
        beginTimeStr = beginTimeStr.replace('月', '-');
        beginTimeStr = beginTimeStr.replace('日', '');
    }

    if (endADateStr == '选择结束日期') {
        endADateStr=nowData;
    } else {
        endADateStr = endADateStr.replace('年', '-');
        endADateStr = endADateStr.replace('月', '-');
        endADateStr = endADateStr.replace('日', '');
    }

    document.getElementById("showHi").innerText =beginTimeStr+" 至 "+ endADateStr+"销售简报";

    beginTimeStr = beginTimeStr.replace(/\-/g,"");

    endADateStr = endADateStr.replace(/\-/g,"");



    var newTime = timeAll(); // ?? $里面是否能访问的奥
    // 拼接时间戳，后台规定
    var timestamp = "strEndDate:" + endADateStr + 'BM' + "strStartDate:" + beginTimeStr + 'BM' + 'timeStamp:' + newTime + 'BM';
    console.log(timestamp)

    // 时间戳md5加密 签名
    var signs = md5(timestamp);
    // 加密后的数据变成大写
    signs = signs.toUpperCase();
    $.ajax({
        type: "get",
        url: webUrl + "firstPage/getFirstPageInfo",
        data: {
            "strEndDate": endADateStr,
            "strStartDate": beginTimeStr,
            "sign": signs,
            "timeStamp": newTime
        },
        dataType: "JSON",
        async: false,
        success: function (data) {
            if (data.status == 200) {
                console.log(data)

                // 拼接字符串（模板字符串）
                // append 我要拼接的是；date 请求过来的东西； 谷歌里面network——》
                //  将这个标签放入到 table 里面；样式可以直接用
                var shopName = data.data.userName + '，欢迎使用百马商户助销系统';

                document.getElementById("ShopName").innerText = shopName;

                // 成功交易报价单的值
                var successStr = '<li>' +
                    '<p>' + data.data.generateNuotationNum +
                    '</p>' +
                    '<span>生成报价单数/单</span>' +
                    '</li>' +
                    '<li>' +
                    '<p>' + data.data.successfulTradingNum +
                    '</p>' +
                    '<span>成功交易客户/个</span>' +
                    '</li>' +
                    '<li>' +
                    '<p>' + data.data.incomeAmount +
                    '</p>' +
                    '<span>提现金额/元</span>' +
                    '</li>' +
                    '<li>' +
                    '<p>' + data.data.sellUpstreamNum +
                    '</p>' +
                    '<span>卖给上游数量/台</span>' +
                    '</li>';
                $('#downName').html(successStr);
            } else if (data.status == 300) {
                window.location.href = 'login.html';
            } else if (data.status == '500') {
                dialog(data.msg);
            }

        },
    });

}

jubgeUser();

// 判断登录用户，是否有快递回收业务
function jubgeUser() {
    var newTime = timeAll();
    var timestamp = 'timeStamp:' + newTime + 'BM';
    var signs = md5(timestamp);
    signs = signs.toUpperCase();
    $.ajax({
        type: 'get',
        url: webUrl + 'firstPage/getStoreSelfInfo',
        data: {
            'timeStamp': newTime,
            'sign': signs,
        },
        dataType: 'JSON',
        async: false,
        success: function (data) {
            console.log(data)
            if (data.status == 200) {
                var supportExpress = data.data.supportExpress;
                if (supportExpress == 1) {
                    // 隐藏我的钱包和卖给上游
                    $('#myWallet').hide();
                    $('#sellUpstream').hide();
                }
                // else if(supportExpress == 2){
                // 默认什么也不做
                // }
            } else if (data.status == 300) {
                window.location.href = 'login.html';
            } else {
                alert(data.msg);
            }
        }
    })
}